package com.open.companymessage.company.feign;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.open.capacity.common.exception.controller.ControllerException;
import com.open.capacity.common.feign.FeignExceptionConfig;
import com.open.capacity.common.model.SysRole;
import com.open.capacity.common.model.SysUser;
import com.open.capacity.common.web.PageResult;
import com.open.capacity.common.web.Result;
import com.open.companymessage.company.feign.fallback.FeignClientFallbackFactory;
import feign.codec.Encoder;
import feign.form.spring.SpringFormEncoder;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
@FeignClient(value="user-center",configuration = FeignExceptionConfig.class ,fallbackFactory = FeignClientFallbackFactory.class, decode404 = true)
@Component("feignService")
public interface FeignService {
    @PostMapping(value = "/user/addSysUser")
    Result addSysUser(@RequestBody SysUser SysUser);
    /**
     * 给用户id添加角色
     * @param id
     * @param roleId
     */
    @PostMapping("/users/roles/com")
    void setRoleToUserFree(@RequestParam("userId") Long id, @RequestParam("roleId") Long roleId);

        /**
         * 后台管理查询角色
         * @param params
         * @return
         * @throws JsonProcessingException
         */
    @GetMapping(value = "/roles")
    PageResult<SysRole> findRoles(@RequestParam Map<String, Object> params) throws ControllerException;

    class MyConfig {
        @Bean
        public Encoder feignFormEncoder() {
            return  new SpringFormEncoder();
        }
    }
}
